package com.smartnsoft.fractory;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;

import com.smartnsoft.droid4me.LifeCycle;
import com.smartnsoft.droid4me.app.SmartSplashScreenActivity;

/**
 * The first activity displayed while the application is loading.
 * 
 * @author Willy Noel
 * @since 2011.05.24
 */
public final class FractorySplashScreenActivity
    extends SmartSplashScreenActivity
    implements LifeCycle.BusinessObjectsRetrievalAsynchronousPolicy
{

  @Override
  protected boolean requiresExternalStorage()
  {
    return false;
  }

  @Override
  protected Class<? extends Activity> getNextActivity()
  {
    return HomeActivity.class;
  }

  @Override
  protected void onRetrieveDisplayObjectsCustom()
  {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(LayoutInflater.from(this).inflate(R.layout.fractory_splash_screen, null));
    setProgressBarIndeterminateVisibility(true);
  }

  @Override
  protected void onRetrieveBusinessObjectsCustom()
      throws BusinessObjectUnavailableException
  {
    try
    {
      Thread.sleep(1500);
    }
    catch (InterruptedException exception)
    {
      if (log.isErrorEnabled())
      {
        log.error("An interruption occurred while displaying the splash screen", exception);
      }
    }
    markAsInitialized();
  }

}
